﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Kooboo.CMS.Content.Models;

namespace KB
{
    public static class ContentBaseExtensions
    {
        #region MapTo

        public static TEntity MapTo<TEntity>(this ContentBase content)
        {
            if (content != null)
            {
                return (TEntity)Activator.CreateInstance(typeof(TEntity), content);
            }
            return default(TEntity);
        }

        public static IEnumerable<TEntity> MapTo<TEntity>(this IEnumerable<ContentBase> contents)
        {
            return contents.Select(it => MapTo<TEntity>(it));
        }

        #endregion
    }
}